A TXT format text file, such as a novel in TXT format, is popular in the field of mobile reading due to its compact file size and wide equipment compatibility. Most TXT text files, such as TXT novels, however, do not have general directories, limiting the ability to quickly locate contents and jump over sections of text in the file during reading process. Existing methods for generating a directory for a TXT text file are based on character matching, i.e., by means of matching all characters in the TXT text file with target characters (such as Chapter X, Article X, etc.). Such methods require conversion of all byte streams in the file into a character string prior to the matching, which is time consuming and inconvenient. Therefore, it is desirable to develop a method and a device to generate a directory rapidly and efficiently. This is especially important in a mobile computing environment because the computing capacity and memory capacity of a mobile apparatus are usually limited.